package com.edward.springdata;

import com.edward.springdata.dao.PersonRepository;
import com.edward.springdata.entity.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import javax.sql.DataSource;
import java.sql.Date;
import java.sql.SQLException;

public class Main {

    private static ApplicationContext ctx ;

    static {
        // 通过静态代码块的方式,让程序加载spring的配置文件
        ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    }


    public static void main(String[] args) throws SQLException {

       /* DataSource dataSouce = (DataSource) ctx.getBean("dataSource");
        System.out.println("数据源："+ dataSouce);
        System.out.println("连接："+ dataSouce.getConnection());*/

        PersonRepository personRepository = ctx.getBean(PersonRepository.class);
       /* Person person = new Person();
        person.setEmail("wangxiaohan@163.com");
        person.setName("wangxiaohan");
        personRepository.save(person);*/

        PageRequest pageRequest = new PageRequest(0,10);
        Page<Person> personList = personRepository.findAll(pageRequest);

        for (Person person : personList){
            System.out.println(person.toString());
        }


    }
}
